<!DOCTYPE html>
<html lang="zh-cn" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
<title th:text="|#{customer.systemTitle}-内容管理-广告管理|">图灵谷</title>
<div th:replace="fragments/head_admin">head</div>
<!--/***** 当前页css  start *****/-->
<!--/***** 当前页css  end *****/-->
</head>
<body>
	<div class="layui-layout layui-layout-admin">
		<div th:replace="fragments/nav_admin">导航栏</div>
		<div th:replace="fragments/menu_admin::menu(parent=content,child=ad)">菜单栏</div>
		<!--/*******内容*******/-->
		<div class="layui-body">
			<div class="layui-main">
				<!--/***** 面包屑 *****/-->
				<div class="layui-elem-quote" style="margin-top: 10px;">
					<span class="layui-breadcrumb"> <a><cite>内容管理</cite></a><a th:href="@{/admin/m/ext/add/list.gsp}">广告管理</a><a><cite>新增</cite></a>
					</span>
				</div>
				<!--/*******操作*******/-->
				<form th:action="@{/admin/m/ext/ad/add.gsp}" id="addForm" role="form" method="post" class="layui-form">
					<fieldset class="layui-elem-field layui-field-title">
						<legend>广告管理-新增</legend>
					</fieldset>
					<div class="layui-form-item">
						<label class="layui-form-label">广告位：<span style="color: red">*</span></label>
						<div class="layui-input-block">
							<select id="typeId" name="adSlotId" lay-verify="required"><option th:if="${result.size()<=0}" value="">暂无</option>
								<option th:each="data : ${result}" th:value="${data.id}" th:text="${data.slotName}"></option></select>
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">广告名称：<span style="color: red">*</span></label>
						<div class="layui-input-block">
							<input type="text" name="adName" required lay-verify="adName" placeholder="请输入广告名称" autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">开始时间：<span style="color: red">*</span></label>
						<div class="layui-input-block">
							<input type="text" name="beginTime" required lay-verify="beginTime" placeholder="yyyy-mm-dd" autocomplete="off" class="layui-input" onclick="layui.laydate({elem: this})">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">结束时间：</label>
						<div class="layui-input-block">
							<input type="text" name="endTime" lay-verify="endTime" placeholder="yyyy-mm-dd" autocomplete="off" class="layui-input" onclick="layui.laydate({elem: this})">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">广告url：<span style="color: red">*</span></label>
						<div class="layui-input-block">
							<input type="text" name="adUrl" required lay-verify="adUrl" placeholder="请输入广告url" autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">广告文字：</label>
						<div class="layui-input-block">
							<input type="text" name="adText" lay-verify="adText" placeholder="请输入广告文字" autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">广告代码：<span style="color: red">*</span></label>
						<div class="layui-input-block">
							<input type="text" name="adScript" required lay-verify="adScript" placeholder="请输入广告代码" autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-form-item layui-form-text">
						<label class="layui-form-label">广告图片:</label>
						<div class="layui-input-block">
							<img id="adIimageShow" width="164"><br /> <input id="adIimage" type="file" name="file" class="layui-upload-file">
						</div>
					</div>
					<div class="layui-form-item layui-form-text">
						<label class="layui-form-label">广告flash:</label>
						<div class="layui-input-block">
							<img id="adFlashShow" width="164"><br /> <input id="adFlash" type="file" name="file" class="layui-upload-file">
						</div>
					</div>
					<div class="layui-form-item">
						<div class="layui-input-block">
							<button class="layui-btn" lay-submit="" lay-filter="submit">立即提交</button>
							<button type="reset" class="layui-btn layui-btn-primary">重置</button>
						</div>
					</div>
				</form>
			</div>
		</div>
		<div th:replace="fragments/footer_admin">底部版权信息等</div>
	</div>
</body>
<div th:replace="fragments/import_js_admin">引入js</div>
<!--/***** 当前页js start *****/-->
<script th:inline="javascript">
    /*<![CDATA[*/
    var form = layui.form();
    var $ = layui.jquery;
    
    layui.use('upload', function() {
        url = BASE_URL + 'admin/m/base/image/uploadImg';
        tg_upload("adIimage", url);
        tg_upload("adFlash", url);
    });
    
    function tg_upload(id, url) {
        $("#" + id).after('<input id="Input'+id+'" type="text" value="" name="'+id+'" hidden="hidden">');
        var fileName;
        //文件上传
        layui.upload({
            url : url,//上传接口
            elem : '#' + id,
            ext : 'jpg|png|gif', //图片格式限制
            before : function(input) {
                layer.msg('文件上传中');
            },
            success : function(res) { //上传成功后的回调
                if(res.success){
                    $("#" + id).parent().next().text("上传成功");
                    $("#Input" + id).attr("value", res.obj);
                    $("#"+id+"Show").attr("src", res.path);
                }
            }
        });
    }
    
  //自定义验证规则
    var rules = {
        adName : function(value) {
            if (value.length <= 0) {
                return '广告名称必填';
            }else if (value.length > 20) {
                return '广告名称在不能超过20个字符';
            }
        },
        adUrl : function(value){
            if(value.length > 40){
                return '广告url不能超过40个字符';
            }else if(!/(^#)|(^http(s*):\/\/[^\s]+\.[^\s]+)/.test(value)){
                return '链接格式不正确'
            }
        },
        beginTime : function(value) {
            if(!/^(\d{4})[-\/](\d{1}|0\d{1}|1[0-2])([-\/](\d{1}|0\d{1}|[1-2][0-9]|3[0-1]))*$/.test(value)){
                return '日期格式不正确';
            }
        },
        endTime : function(value) {
            if (value.length > 0) {
                if(!/^(\d{4})[-\/](\d{1}|0\d{1}|1[0-2])([-\/](\d{1}|0\d{1}|[1-2][0-9]|3[0-1]))*$/.test(value)){
                    return '日期格式不正确';
                }
            }
        },
        adText : function(value) {
            if (value.length > 50) {
                return '广告文字不能超过50个字符';
            }
        },
        adScript : function(value) {
            if (value.length <= 0 || value.length > 20) {
                return '广告代码必填';
            }else if(value.length > 20){
                return '广告代码不能超过20个字符';
            }
        }
    };
    form.verify(rules);
    /*]]>*/
</script>
<!--/***** 当前页js end *****/-->
</html>